//
//  Channel_TableViewCell.m
//  NewMyMusicAPP
//
//  Created by dlios on 15/6/26.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "Channel_TableViewCell.h"

@implementation Channel_TableViewCell

- (void)dealloc
{

    [_channelM release];
    [_title release];
    [_artistName release];
    [_playListPic release];
    [super dealloc];
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self createSubviews];
    }
    
    return self;
}

- (void)createSubviews
{
    self.playListPic = [[[UIImageView alloc] initWithFrame:CGRectMake(WIDTH * 5,HEIGHT * 5,WIDTH * 170,HEIGHT * 100)]autorelease];
    self.playListPic.backgroundColor = [UIColor blackColor];
    [self.contentView addSubview:self.playListPic];
    
    self.title = [[[UILabel alloc] initWithFrame:CGRectMake(WIDTH * 190,HEIGHT * 30,WIDTH * 130,HEIGHT * 30)]autorelease];
    self.title.backgroundColor = [UIColor clearColor];
    self.title.textColor = [UIColor whiteColor];
    [self.title setFont:[UIFont fontWithName:@"Helvetica-Bold" size:15]];//加粗字体
    [self.contentView addSubview:self.title];
    
    self.artistName = [[[UILabel alloc] initWithFrame:CGRectMake(WIDTH * 190,HEIGHT * 50,WIDTH * 130,HEIGHT * 30)]autorelease];
    self.artistName.backgroundColor = [UIColor clearColor];
    self.artistName.textColor = [UIColor orangeColor];
    [self.artistName setFont:[UIFont fontWithName:@"Helvetica-Bold" size:15]];//加粗字体
    [self.contentView addSubview:self.artistName];
    
    self.button = [UIButton buttonWithType:UIButtonTypeCustom];
    self.button.frame = CGRectMake(WIDTH * 330, HEIGHT * 35, WIDTH * 25, WIDTH * 25);
    [self.button setBackgroundImage:[UIImage imageNamed:@"circlelist_heart@3x.png"] forState:UIControlStateNormal];
    [self.button addTarget:self action:@selector(collect) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.button];
    
    
}

- (void)setChannelM:(Channel_Model *)channelM
{
    if (_channelM != channelM) {
        [_channelM release];
        _channelM = [channelM retain];
    }
    
    NSURL *url = [NSURL URLWithString:self.channelM.playListPic];
    [self.playListPic sd_setImageWithURL:url placeholderImage:nil];
    
    self.title.text = self.channelM.title;
    self.artistName.text = self.channelM.artistName;
    
    
    if (self.buer == YES) {
        [self.button setBackgroundImage:[UIImage imageNamed:@"circlelist_heartup@3x.png"] forState:UIControlStateNormal];
        
        
    }else
    {
        [self.button setBackgroundImage:[UIImage imageNamed:@"circlelist_heart@2x.png"] forState:UIControlStateNormal];
        
    }

    
}

-(void)collect
{
    
    CollectModel *collect = [[[CollectModel alloc] init]autorelease];
    collect.title = self.channelM.title;
    collect.modelId = self.channelM.Id;
    NSLog(@"id = %@",self.channelM.Id);
    collect.type = @"VIDEO";
    if (self.buer == NO) {
        [self.button setBackgroundImage:[UIImage imageNamed:@"circlelist_heartup@3x.png"] forState:UIControlStateNormal];
        [[DataHandle shareHandleController] insertCollect:collect];
        self.buer = YES;
        NSLog(@"添加收藏 NO  ==  id = %@",collect.modelId);
    }else
    {
        [self.button setBackgroundImage:[UIImage imageNamed:@"circlelist_heart@3x.png"] forState:UIControlStateNormal];
        [[DataHandle shareHandleController] deleteTable:collect.modelId];
        self.buer = NO;
        NSLog(@"删除收藏 YES ==  id = %@",collect.modelId);
    }
    
    
    
    
}






- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
